﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.Configuration;

namespace wdss.WebServices
{
    /// <summary>
    /// Summary description for AddToDepartment
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class AddToDepartment : System.Web.Services.WebService
    {

        public AddToDepartment()
        { 
        }
        public void Add(String username, int department)
        {
            int userid=0;
            SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString);
            SqlCommand command = new SqlCommand("sp_GetUserID", connect);
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Parameters.Add("@par_email", System.Data.SqlDbType.NChar).Value = username;
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            try
            {
                connect.Open();
                userid = (int)command.ExecuteScalar();
                connect.Close();
                connect.Dispose();
            }
            catch (Exception e)
            { }
            SqlConnection connect1 = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString);
            SqlCommand command1 = new SqlCommand("sp_AddUserDepartment", connect1);
            command1.CommandType = System.Data.CommandType.StoredProcedure;
            command1.Parameters.Add("@par_userid", System.Data.SqlDbType.Int).Value = userid;
            command1.Parameters.Add("@par_deptid", System.Data.SqlDbType.Int).Value = department;
            SqlDataAdapter adapter1= new SqlDataAdapter(command1);
            try
            {
                connect1.Open();
                command1.ExecuteNonQuery();
                connect1.Close();
                connect1.Dispose();
            }
            catch (Exception e)
            { }

        }
    }
}
